package com.kitty.game.wuhun;

import com.kitty.common.cache.RedisService;
import com.kitty.game.hunpo.message.StringIntValue;
import com.kitty.game.role.model.Role;
import com.kitty.game.role.service.RoleService;
import com.kitty.mina.cache.DataCache;
import com.kitty.mina.message.MessagePusher;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * WuHunService_
 *
 * @author StanWind
 * @create 2022 - 00 - 00 1:19 AM
 */
@Service
@Slf4j
public class WuHunService_ {
    Logger logger = LoggerFactory.getLogger(getClass());
    //属性map
    public static final Map<Integer, List<StringIntValue>> PROP_MAP = new HashMap<>();
    //升级所需阴德
    public static final Map<Integer, Integer> UP_REQUIRE_MAP = new HashMap<>();
    //最大阴德
    public static final Integer MAX_WKZ_DE = 2000000000;
    @Autowired
    RoleService roleService;
    @Autowired
    RedisService redisService;
    public void loadWuhun(){
        //阶段 影响系数
        float param = 1.0f;
        for (int i = 0; i < 10; i++) {
            int s = i + 1;
            List<StringIntValue> stage = new ArrayList<>();
            /*
             * 这里是魂魄属性  有算法  所有的数字 public class StringIntValue *3  了
             */
            stage.add(new StringIntValue("phy_power", Math.round(param * s * Integer.parseInt(DataCache.REDIS_DATA.get("wuhun_jiacheng_1").toString()))));
            stage.add(new StringIntValue("mag_power", Math.round(param * s * Integer.parseInt(DataCache.REDIS_DATA.get("wuhun_jiacheng_2").toString()))));
            stage.add(new StringIntValue("def", Math.round(param * s * Integer.parseInt(DataCache.REDIS_DATA.get("wuhun_jiacheng_3").toString()))));

            stage.add(new StringIntValue("phy_power", Math.round(param * s * Integer.parseInt(DataCache.REDIS_DATA.get("wuhun_jiacheng_4").toString()))));
            stage.add(new StringIntValue("speed", Math.round(param * s * Integer.parseInt(DataCache.REDIS_DATA.get("wuhun_jiacheng_5").toString()))));
            stage.add(new StringIntValue("mag_power", Math.round(param * s * Integer.parseInt(DataCache.REDIS_DATA.get("wuhun_jiacheng_6").toString()))));
            stage.add(new StringIntValue("def", Math.round(param * s * Integer.parseInt(DataCache.REDIS_DATA.get("wuhun_jiacheng_7").toString()))));

            stage.add(new StringIntValue("phy_power", Math.round(param * s * Integer.parseInt(DataCache.REDIS_DATA.get("wuhun_jiacheng_8").toString()))));
            stage.add(new StringIntValue("mag_power", Math.round(param * s * Integer.parseInt(DataCache.REDIS_DATA.get("wuhun_jiacheng_9").toString()))));
            stage.add(new StringIntValue("speed", Math.round(param * s * Integer.parseInt(DataCache.REDIS_DATA.get("wuhun_jiacheng_10").toString()))));
            PROP_MAP.put(s, stage);
        }
        //十阶
        for (int i = 0; i < 10; i++) {
            int s = i + 1;
            double value = Math.round(Integer.parseInt(DataCache.REDIS_DATA.get("wuhun_xiaohao").toString()) * s);
            UP_REQUIRE_MAP.put(s, (int) value);
        }
    }

    /**
     * 获取武魂层增益属性
     *
     * @param level
     * @return
     */
    public List<StringIntValue> getAddProp(int level) {
        return PROP_MAP.get(level);
    }

    /**
     * 升级所需武灵值
     *
     * @param level      神魂阶
     * @param levelInner 神魂子阶
     * @return
     */
    public int getStageUpReq(int level, int levelInner) {
        return UP_REQUIRE_MAP.getOrDefault(level, 15);
    }


    /**
     * 加成面板包
     *
     * @param hunPoProp
     */
    public ResWhunPoPanelData getPanelPropResp(WuHunPoProp wuhunPoProp) {
        ResWhunPoPanelData data = new ResWhunPoPanelData();
       data.setPhyPower(wuhunPoProp.getPhyPower());
       data.setMagPower(wuhunPoProp.getMagPower());
        data.setDefense(wuhunPoProp.getDefense());
       // //data.setLife(hunPoProp.getLife());
       data.setSpeed(wuhunPoProp.getSpeed());
        data.setList(getAddProp(Math.min(wuhunPoProp.getLevel(), 10)));

        return data;
    }
    public WuHunPoProp getWuHunPoProp(Role role) {
        WuHunPoProp wuHunPoProp = role.getExtendBox().getWuHunPoProp();
        if (wuHunPoProp == null) {
            //数据初始化
            wuHunPoProp = new WuHunPoProp();
            role.getExtendBox().setWuHunPoProp(wuHunPoProp);
            wuHunPoProp.setLevel(1);
            wuHunPoProp.setLevelInner(0);
            ////初始化武灵值
            wuHunPoProp.setWulingzhi(0);
            role.save();
        }

        return wuHunPoProp;
    }

    /**
     * 发送武魂面板
     *
     * @param role
     */
    public void sendPanel(Role role) {


        ResWhunPoPanelData resWhunPoPanelData = getPanelPropResp(getWuHunPoProp(role));


      //  WuHunService_ wuHunService_ = SpringUtils.getBean(WuHunService_.class);

       // //魂窍属性显示
       // HunQiaoToSave hunQiaoToSave =  wuHunService_.hunQiaoToSave(role.getRoleId());

        // 显示仓库信息
        //List<HunQiaoStoreEquipInfo> cangKus = hunQiaoToSave.getCangKus();
       // HunQiaoCangKu hunQiaoCangKu = new HunQiaoCangKu();
       // hunQiaoCangKu.setStr("tyzq_store");
       // hunQiaoCangKu.setList(cangKus);
       // hunQiaoCangKu.addMore();
       // MessagePusher.pushMessage(role, hunQiaoCangKu);


       // List<HunQiaoField> hunQiaoFields = hunQiaoService.hunQiaoFields(hunQiaoToSave);
       // respHunPoPanelData.setHunQiaoAllProps(hunQiaoFields.stream().map(HunQiaoField::toHunQiaoAllProps).collect(Collectors.toList()));
       // SpringUtils.getBean(HunQiaoService.class).sendZhuRu(role,hunQiaoToSave);

        MessagePusher.pushMessage(role, resWhunPoPanelData);

        roleService.sendYinDe(role);

    }

    /**
     * 计算增加属性
     *
     * @param hunPoProp
     */
    public void calcAddedProp(WuHunPoProp wuHunPoProp) {
        StringIntValue si = null;
        if (wuHunPoProp.getLevelInner() == 0) {
            si = getAddProp(wuHunPoProp.getLevel() - 1).get(9);
        } else {
            si = getAddProp(wuHunPoProp.getLevel()).get(wuHunPoProp.getLevelInner() - 1);
        }
        if ("phy_power".equals(si.getPropName())) {
            wuHunPoProp.setPhyPower(wuHunPoProp.getPhyPower() + si.getPropValue());
        } else if ("mag_power".equals(si.getPropName())) {
            wuHunPoProp.setMagPower(wuHunPoProp.getMagPower() + si.getPropValue());
        } else if ("max_life".equals(si.getPropName())) {
         //   wuHunPoProp.se(wuHunPoProp.getLife() + si.getPropValue());
        } else if ("def".equals(si.getPropName())) {
            wuHunPoProp.setDefense(wuHunPoProp.getDefense() + si.getPropValue());
        } else if ("speed".equals(si.getPropName())) {
            wuHunPoProp.setSpeed(wuHunPoProp.getSpeed() + si.getPropValue());
        }
    }



}
